#include "ForwardAI.h"

#include "Monster.h"
#include "Tile.h"


ForwardAI::ForwardAI(const Monster& monster, const Map& map):
	MonsterAI(monster, map)
{
}


ForwardAI::~ForwardAI()
{
}


void ForwardAI::getMove(int& hDirection, int& vDirection) const
{
	// Query current location and direction
	int currentHDirection, currentVDirection;
	monster.getVelocity(currentHDirection, currentVDirection);
	int currentX, currentY;
	monster.getLocation(currentX, currentY);
	// New positions in current direction.
	int newX = currentX + currentHDirection;
	int newY = currentY + currentVDirection;
	// Move if this tile is empty.
	if (map.isWithinBounds(newX, newY) &&
		map[newY][newX]->isPassable(&monster))
	{
		hDirection = currentHDirection;
		vDirection = currentVDirection;
	}
	else
	{
		// Else look for another valid direction.
		hDirection = currentHDirection;
		vDirection = currentVDirection;
		getRandomOtherValidDirection(currentX, currentY, hDirection, vDirection);
	}
}
